<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>care</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		#searchForm div.ui-input-text {
			padding: 0.4em;
			display:inline-block;
		}
		#searchForm div.ui-input-button {
			padding: 0.4em;
			display:inline-block;
		}
	</style>
	
</head>
<body>
	<tags:breadcrumb name="breadcrumb" />
	<div class="icon-buttons">
		<a id="return" data-role="button" data-icon="back" data-iconpos="notext" data-inline="true" href="#">返回</a>
	</div>
	<form:form id="detailForm" modelAttribute="" action="${ctx}/report/all/careDetail" method="post" data-ajax="false">
		<input type="hidden" id = "careId" name="careId">
		<input type="hidden" id = "detailStart" name="startDate">
		<input type="hidden" id = "detailEnd" name="endDate">
	</form:form>
	<form:form id="searchForm" modelAttribute="" action="${ctx}/report/all/care" method="post" class="middleCls" data-ajax="false">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<label>开始日期：</label>
		<input type="date" id="startDate" data-inline="true" name="startDate" value="${startDate}"/>
		<label>结束日期：</label>
		<input type="date" id="endDate" data-inline="true" name="endDate" value="${endDate}"/>
		<input data-inline="true" type="submit" value="查询"/>
	</form:form>
	<tags:message content="${message}"/>
	<div class="form-input">
		<div class="middleCls">提示：如果没有输入查询的开始和结束时间，默认显示最近7天的记录</div>
		<h3 class="middleCls">护理统计列表</h3>
		<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
			<thead><tr><th>护理名称</th><th>数量</th><th>总价</th></tr></thead>
			<tbody>
			<c:forEach items="${page.list}" var="reportCare">
				<tr id="${reportCare.care.id}">
					<c:if test="${reportCare.care.care_type == 0}">
						<td>${reportCare.care.care.name}</td>
					</c:if>
					<c:if test="${reportCare.care.care_type == 1}">
						<td>${reportCare.care.storeSelfCare.name}</td>
					</c:if>
					<td>${reportCare.saleNumber}</td>
					<td>${reportCare.totalPrice}</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
		<div class="pagination">${page}</div>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
			jQuery("#searchForm").validate({
		 		submitHandler: function(form){
		 			var startValue = $("#startDate").val();
					if (!startValue){
						showTip("开始日期必须填写!");
						return;
					}
					var endValue = $("#endDate").val();
					if (!endValue){
						showTip("结束日期必须填写!");
						return;
					}
					if(startValue && endValue){
						 var start = new Date(startValue.replace(/-/g, "/"));
						 var end = new Date(endValue.replace(/-/g, "/"));
						 if (end < start) {
							showTip("结束日期不能大于开始日期!");
							return;
						}
					 }
					 loading("正在提交，请稍等...");
					 form.submit();
				}
	        });
		 	$("#contentTable tbody tr").click(function(e){
				if (!this.id) {
					return;
				}
				sessionStorage.reportStartSecond = $("#startDate").val();
				sessionStorage.reportEndSecond = $("#endDate").val();
				$("#contentTable tbody tr").removeClass("select_active");
				$(this).addClass("select_active");
				reportDetail(this.id);
			});
	        loadingSortTable("contentTable");
	        addParentPageNo();
		});
        function reportDetail(id){
            $("#careId").val(id);
            $("#detailStart").val($("#startDate").val());
            $("#detailEnd").val($("#endDate").val());
        	$("#detailForm").submit();
        }
        function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
        function addParentPageNo() {
			var hasParent = sessionStorage.hasParent;
			var returnHref = "${ctx}";
			if (hasParent){
				var reportStart = sessionStorage.reportStart;
				var reportEnd = sessionStorage.reportEnd;
				returnHref = "${ctx}/report/all/list?startDate=" +reportStart + "&endDate=" +reportEnd;
			}
			$("#return").attr("href", returnHref);
		}
	</script>
</body>
</html>
